﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HWR_Ants.Classes.Obsolete
{
    [Obsolete]
    class Ant
    {
        string startPoint;
        string currentPosition;
        SortedList<string, bool> hasVisited;
        SortedList<string, PointWithDistances> distances;

        public Ant(string id, PointWithDistances[] points)
        {
            startPoint = id;
            currentPosition = id;
            distances = new SortedList<string, PointWithDistances>();
            hasVisited = new SortedList<string, bool>();
            foreach (PointWithDistances p in points)
            {
                if (p.Id != startPoint)
                    hasVisited.Add(p.Id, false);
                else
                    hasVisited.Add(p.Id, true);

                distances.Add(p.Id, p);
            }

            laufe();
        }

        private void laufe()
        {
            int counter = hasVisited.Count - 1;
            double summe = 0;
            while (counter > 0)
            {
                string id = getNextCity();
                PointWithDistances pwd;
                distances.TryGetValue(currentPosition, out pwd);
                hasVisited[id] = true;
                summe += pwd.getDistance(id);
                // distances.Remove(id);
                currentPosition = id;
                counter--;
            }
            PointWithDistances pwd2;
            distances.TryGetValue(currentPosition, out pwd2);
            summe += pwd2.getDistance(startPoint);
        }

        private string getNextCity()
        {
            PointWithDistances val;
            distances.TryGetValue(currentPosition, out val);
            double bestDistance = 0;
            string bestNextCity = String.Empty;

            foreach (string keys in val.ListOfDistances.Keys)
            {
                bool visited;
                hasVisited.TryGetValue(keys, out visited);

                if (!visited)
                {
                    double tempValue;
                    val.ListOfDistances.TryGetValue(keys, out tempValue);

                    if (tempValue < bestDistance || bestDistance <= 0)
                    {
                        bestDistance = tempValue;
                        bestNextCity = keys;
                    }
                }
            }

            // hasVisited.Remove(bestNextCity);

            return bestNextCity;
        }
    }
}
